<?php 
/**
* 
*/
class InversionesController extends Sgit_Controller_Action
{

    protected $_main_model='Inversiones';
    protected $_main_form='Inversiones';

    
    function _begin()
    {
        $this->_file_upload[1] = Sgit_Util_FileUpload::run('inversion','peticion');
        $this->_file_upload[2] = Sgit_Util_FileUpload::run('inversion','aprobacion');
        $this->_file_upload[3] = Sgit_Util_FileUpload::run('inversion','noc');
    }
    

    public function indexAction()
    {
      
        $this->setParam('anio',date('Y'));
      
        $filtros = new Sgit_Form_Filtros();
        $f_anio = new Sgit_Form_Element_Select_Year('anio');
        $filtros->addFormSelect($f_anio);
        $filtros->myRender();

        $values = $this->_getFiltrosValues($filtros);

        $this->view->rows = $this->_model->default->getInversiones($values);
        

        
    }
	
    public function editarAction()
    {

        $this->_editar();
    }
    
    public function insertarAction()
    {
        $this->_insertar();
    }
    
    public function borrarAction()
    {
        $this->_borrar();
    }
    
    protected function _prepareValuesToDb()
    {
        
        $row=$this->_form->getValues();

        
        Sgit_Util_removeFiles::run($this->_file_upload[1]['tabla'],$this->_file_upload[1]['key'],$this->_id,$row[$this->_file_upload[1]['activo']]);
        unset($row[$this->_file_upload[1]['name']]);
        unset($row[$this->_file_upload[1]['activo']]);
        
        Sgit_Util_removeFiles::run($this->_file_upload[2]['tabla'],$this->_file_upload[2]['key'],$this->_id,$row[$this->_file_upload[2]['activo']]);
        unset($row[$this->_file_upload[2]['name']]);
        unset($row[$this->_file_upload[2]['activo']]);
        
        Sgit_Util_removeFiles::run($this->_file_upload[3]['tabla'],$this->_file_upload[3]['key'],$this->_id,$row[$this->_file_upload[3]['activo']]);
        unset($row[$this->_file_upload[3]['name']]);
        unset($row[$this->_file_upload[3]['activo']]);
        
        return $row;
    }

	
}


